import Vue from 'vue'
import App from './App'
import router from './router/index'
import store from './store/index'
import axios from 'axios'

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})

// 使用全局axios
// axios的配置信息
axios.defaults.baseURL = 'http://123.207.32.32:8000';
// axios.defaults.timeout = 5000

// 发送一个请求
axios({
  url:'/home/multidata'
}).then(res =>{
  if(res){
    // console.log(res);
  }
})

// 发送并发请求,用法等同于Promise.all()
axios.all([
  axios({url:'/home/multidata'}),
  axios({url:'/home/data'}),
  axios({url:'/category'})
]).then(res =>{
  if(res){
    // console.log(...res);
  }
})

// 创建对应的axios实例
const instance1 = axios.create({
  baseURL : 'http://123.207.32.32:8000',
timeout : 5000
})
instance1({
  url:'/home/multidata'
}).then(res =>{
  // console.log(res);
})

// 使用request.js中的实例,封装request模块
import {request} from './network/request.js'
request({
  url:'/home/multidata'
}).then(res =>{
  console.log(res);
}).catch(err =>{
  console.log(err);
})